package com.zy.je.common.mybatis.ext.injector;

import com.baomidou.mybatisplus.core.injector.AbstractMethod;
import com.baomidou.mybatisplus.core.injector.AbstractSqlInjector;
import com.baomidou.mybatisplus.core.injector.methods.*;
import com.baomidou.mybatisplus.core.metadata.TableInfo;
import com.zy.je.common.mybatis.ext.injector.methods.*;

import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;

public class ExtSqlInjector extends AbstractSqlInjector {

    @Override
    public List<AbstractMethod> getMethodList(Class<?> mapperClass, TableInfo tableInfo) {
//        return Stream.of(
//                new Insert(),
//                new ExtDelete(),
//                new ExtDeleteByMap(),
//                new ExtDeleteById(),
//                new ExtDeleteBatchByIds(),
//                new Update(),
//                new UpdateById(),
//                new SelectById(),
//                new SelectBatchByIds(),
//                new SelectByMap(),
//                new SelectOne(),
//                new SelectCount(),
//                new SelectMaps(),
//                new SelectMapsPage(),
//                new SelectObjs(),
//                new SelectList(),
//                new SelectPage(),
//                //根据ID查询数据，无视逻辑删除字段
//                new SelectByIdWithDeleted(),
//                //根据ID删除数据，真实删除
//                new RemoveRealById()
//        ).collect(toList());

        Stream.Builder<AbstractMethod> builder =
                Stream.<AbstractMethod>builder()
                        .add(new Insert())
                        .add(new ExtDelete())
                        .add(new ExtDeleteByMap())
                        .add(new Update())
                        .add(new SelectByMap())
                        .add(new SelectCount())
                        .add(new SelectMaps())
                        .add(new SelectMapsPage())
                        .add(new SelectObjs())
                        .add(new SelectList())
                        .add(new SelectPage())
                        //根据ID查询数据，无视逻辑删除字段
                        .add(new SelectByIdWithDeleted())
                ;
        if (tableInfo.havePK()) {
            builder.add(new ExtDeleteById())
                    .add(new ExtDeleteBatchByIds())
                    .add(new UpdateById())
                    .add(new SelectById())
                    .add(new SelectBatchByIds())
                    //根据ID删除数据，真实删除
                    .add(new RemoveRealById())
            ;
        } else {
            this.logger.warn(String.format("%s ,Not found @TableId annotation, Cannot use Mybatis-Plus 'xxById' Method.", tableInfo.getEntityType()));
        }

        return builder.build().collect(Collectors.toList());
    }
}
